import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xuance/constant.dart';

import 'logic.dart';

class MainPage extends StatelessWidget {
  const MainPage({super.key});

  @override
  Widget build(BuildContext context) {
    final MainLogic logic = Get.find<MainLogic>();
    final state = logic.state;
    return Scaffold(
      backgroundColor: bgColor,
      body: Obx(() {
        return PageView(
            controller: logic.pageController,
            onPageChanged: (p) {
              logic.changePage(p, false);
            },
            children: state.pages.map((element) => element.page).toList());
      }),
      bottomNavigationBar: Obx(() {
        return BottomNavigationBar(
            backgroundColor: Colors.black45,
            items: state.pages.map((element) => element.bottom).toList(),
            currentIndex: state.currentIndex.value,
            selectedLabelStyle: const TextStyle(fontWeight: FontWeight.w600),
            selectedItemColor: Colors.white,
            unselectedItemColor: Colors.grey,
            selectedIconTheme: IconThemeData(color: c_green),
            onTap: (i) {
              logic.changePage(i, true);
            },
            type: BottomNavigationBarType.fixed);
      }),
    );
  }
}
